home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / idcmp.lzh / IDCMP / Example3.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  5KB  |  158 lines

  1. /* Example3                                                   */
  2. /* This program explains how to use the IDCMP flags: NEWSIZE, */
  3. /* ACTIVEWINDOW and INACTIVEWINDOW.                           */
  4.  
  5.  
  6.  
  7. #include <intuition/intuition.h>
  8.  
  9.  
  10.  
  11. struct IntuitionBase *IntuitionBase;
  12.  
  13.  
  14.  
  15. /* Declare a pointer to a Window structure: */ 
  16. struct Window *my_window;
  17.  
  18. /* Declare and initialize your NewWindow structure: */
  19. struct NewWindow my_new_window=
  20. {
  21.   50,             /* LeftEdge    x position of the window. */
  22.   25,             /* TopEdge     y positio of the window. */
  23.   320,            /* Width       320 pixels wide. */
  24.   100,            /* Height      100 lines high. */
  25.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  26.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  27.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user: */
  28.                   /*             selects the Close window gad, or when    */
  29.  
  30.   NEWSIZE|        /*             the user resizes the window.             */
  31.   ACTIVEWINDOW|   /*             We will also recieve a message whenever  */
  32.   INACTIVEWINDOW, /*             the window is activated/deactivated.     */
  33.  
  34.   SMART_REFRESH|  /* Flags       Intuition should refresh the window. */
  35.   WINDOWCLOSE|    /*             Close Gadget. */
  36.   WINDOWDRAG|     /*             Drag gadget. */
  37.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  38.   WINDOWSIZING|   /*             Sizing Gadget. */
  39.   ACTIVATE,       /*             The window should be Active when opened. */
  40.   NULL,           /* FirstGadget No gadgets connected to this window. */
  41.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  42.   "PLAY WITH WINDOWS", /* Title  Title of the window. */
  43.   NULL,           /* Screen      Connected to the Workbench Screen. */
  44.   NULL,           /* BitMap      No Custom BitMap. */
  45.   100,            /* MinWidth    We will not allow the window to become */
  46.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  47.   400,            /* MaxWidth    than 400 x 200. */
  48.   200,            /* MaxHeight */
  49.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  50. };
  51.  
  52.  
  53.  
  54. main()
  55. {
  56.   /* Boolean variable used for the while loop: */
  57.   BOOL close_me;
  58.  
  59.   ULONG class; /* IDCMP flag. */
  60.  
  61.   /* Pointer to an IntuiMessage structure: */
  62.   struct IntuiMessage *my_message;
  63.  
  64.  
  65.  
  66.   /* Before we can use Intuition we need to open the Intuition Library: */
  67.   IntuitionBase = (struct IntuitionBase *)
  68.     OpenLibrary( "intuition.library", 0 );
  69.   
  70.   if( IntuitionBase == NULL )
  71.     exit(); /* Could NOT open the Intuition Library! */
  72.  
  73.  
  74.  
  75.   /* We will now try to open the window: */
  76.   my_window = (struct Window *) OpenWindow( &my_new_window );
  77.   
  78.   /* Have we opened the window succesfully? */
  79.   if(my_window == NULL)
  80.   {
  81.     /* Could NOT open the Window! */
  82.     
  83.     /* Close the Intuition Library since we have opened it: */
  84.     CloseLibrary( IntuitionBase );
  85.  
  86.     exit();  
  87.   }
  88.  
  89.  
  90.  
  91.   /* We have opened the window, and everything seems to be OK. */
  92.  
  93.   printf("Play with the window!\n\n");
  94.  
  95.  
  96.  
  97.   close_me = FALSE;
  98.  
  99.   /* Stay in the while loop until the user has selected the Close window */
  100.   /* gadget: */
  101.   while( close_me == FALSE )
  102.   {
  103.     /* Wait until we have recieved a message: */
  104.     Wait( 1 << my_window->UserPort->mp_SigBit );
  105.  
  106.  
  107.     /* As long as we can collect messages successfully we stay in the */
  108.     /* while-loop: */
  109.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  110.     {
  111.       /* After we have successfully collected the message we can read */
  112.       /* it, and save any important values which we maybe want to check */
  113.       /* later: */
  114.       class = my_message->Class;  /* IDCMP flag. */
  115.  
  116.  
  117.       /* After we have read it we reply as fast as possible: */
  118.       /* REMEMBER! Do never try to read a message after you have replied! */
  119.       /* (Some other process has maybe changed it.) */
  120.       ReplyMsg( my_message );
  121.  
  122.  
  123.       /* Check which IDCMP flag was sent: */
  124.       switch( class )
  125.       {
  126.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  127.                close_me=TRUE;
  128.                break;
  129.         
  130.         case NEWSIZE:        /* The user resized the window. */
  131.                printf("The window was resized!\n");
  132.                printf("Width: %d\n", my_window->Width);
  133.                printf("Height: %d\n\n", my_window->Height);
  134.                break;
  135.  
  136.         case ACTIVEWINDOW:   /* Window actiavted. */
  137.                printf("Window activated!\n\n");
  138.                break;
  139.  
  140.         case INACTIVEWINDOW: /* Window inactiavted. */
  141.                printf("Window inactivated!\n\n");
  142.                break;
  143.       }
  144.     }
  145.   }
  146.  
  147.  
  148.  
  149.   /* Close the window: */
  150.   CloseWindow( my_window );
  151.  
  152.  
  153.  
  154.   /* Close the Intuition Library: */
  155.   CloseLibrary( IntuitionBase );
  156.   
  157.   /* THE END */
  158. }